package com.java_exam.java_exam.component;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

//区域语言组件
public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String l = request.getParameter("l"); //获取传来的区域语言信息
        Locale locale = Locale.getDefault();   //先设置为默认
        if(!StringUtils.isEmpty(l)){   //判断 l 不为空
            String[] split = l.split("_");  //根据 _ 拆分
            locale = new Locale(split[0],split[1]);  //对应语言  地区
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
